<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$module = get('module');
$method = get('method');
$id = get('id');

$moduleObj = JFX_Module::getInstance($module);

// try for block id
$BLOCK = new JFX_Block;
$res = $BLOCK->loadById($id, '', false, true);
$content = '';

if($res){
    // ok it is a block
    
    $blockid = $id;

    ob_start();
    $moduleObj->$method($BLOCK);
    $content = ob_get_contents();
    ob_end_clean();

}else{
    // try for page id
    $PAGE = new JFX_Page;
    $res = $PAGE->loadById($id);
    if(!$res){
        // no can do
        while(ob_get_level()>0) ob_end_clean();
        die(json_encode(array()));
    }
    $pageid = $id;

    ob_start();
    $moduleObj->$method($PAGE);
    $content = ob_get_contents();
    ob_end_clean();

}

$res = new stdClass();

if(is_object($moduleObj)){
    
    
    $js = $VIEW->getJs();
    $dom = phpQuery::newDocumentXhtml($js);
    
    $res->js = (string) pq('script');
    $res->error = JFX::getError();
    $res->success = JFX::getSuccess();
    $res->content = $content;
}else{
    $res->content = 'Invalid method for this module';
    $res->js = '';
}

while(ob_get_level()>0) ob_end_clean();

die(json_encode($res));




